package org.fyp.synchrona.moodle.service;

import org.apache.log4j.Logger;
import org.fyp.synchrona.core.info.impl.ICommonDataObject;
import org.fyp.synchrona.moodle.service.util.NewData;
import org.fyp.synchrona.moodle.service.util.OldData;

public class NewDataProcessor{
	
	public NewData newDataObj;
	
	public OldData oldDataObj;
	
	static final Logger logger = Logger.getLogger(NewDataProcessor.class);
	
	public NewDataProcessor(OldData oldDataObj, NewData newDataObj) {
		this.newDataObj = newDataObj;
		this.oldDataObj = oldDataObj;
	}
	public void createUpdateObj(ICommonDataObject cdo) {
		
		newDataObj.setMAX_FILE_SIZE(oldDataObj.getMAX_FILE_SIZE());
		newDataObj.setID(oldDataObj.getID());
		newDataObj.setCourse(oldDataObj.getCourse());
		newDataObj.setmform_showadvanced_last(oldDataObj.getmform_showadvanced_last());
		newDataObj.setSessionKey(oldDataObj.getSessionKey());
		newDataObj.set_qf__user_editadvanced_form(oldDataObj.get_qf__user_editadvanced_form());
		newDataObj.setmform_showadvanced(oldDataObj.getmform_showadvanced());
		if(cdo.getUSER_NAME()!=null){
			newDataObj.setusername(cdo.getUSER_NAME());
			logger.info("[MOODLE] username ::"+cdo.getUSER_NAME());
		}else{
			logger.info("[MOODLE] username ::"+oldDataObj.getusername());
			newDataObj.setusername(oldDataObj.getusername());
		}
		
		if(cdo.getFIRST_NAME()!=null){
			newDataObj.setfirstname(cdo.getFIRST_NAME());
		}else{
			newDataObj.setfirstname(oldDataObj.getfirstname());
		}
		
		if(cdo.getLAST_NAME()!=null){
			newDataObj.setlastname(cdo.getLAST_NAME());
		}else{
			newDataObj.setlastname(oldDataObj.getlastname());
		}
		
		if(cdo.getEMAIL()!=null){
			newDataObj.setemail(cdo.getEMAIL());
			
		}else{
			newDataObj.setemail(oldDataObj.getemail());
			
		}
		
		newDataObj.setmaildisplay(oldDataObj.getmaildisplay());
		newDataObj.setemailstop(oldDataObj.getemailstop());
		newDataObj.setmailformat(oldDataObj.getmailformat());
		newDataObj.setmaildigest(oldDataObj.getmaildigest());
		newDataObj.setautosubscribe(oldDataObj.getautosubscribe());
		newDataObj.settrackforums(oldDataObj.gettrackforums());
		newDataObj.sethtmleditor(oldDataObj.gethtmleditor());
		newDataObj.setajax(oldDataObj.getajax());
		newDataObj.setscreenreader(oldDataObj.getscreenreader());
		//System.out.println(oldDataObj.getcity());
		if(cdo.getCITY()!=null){
			newDataObj.setcity(cdo.getCITY());
			
		}else{
			newDataObj.setcity(oldDataObj.getcity());
			logger.info("[MOODLE] CITY ::"+oldDataObj.getcity());
		}
		
		if(cdo.getCOUNTRY()!=null){
			newDataObj.setcountry(cdo.getCOUNTRY());
			
		}else{
			newDataObj.setcountry(oldDataObj.getcountry());
			logger.info("[MOODLE] country ::"+oldDataObj.getcountry());
		}
		
		newDataObj.settimezone(oldDataObj.gettimezone());
		
		if(cdo.getBIO()!=null){
			newDataObj.setdescription(cdo.getBIO());
			
		}else{
			newDataObj.setdescription(oldDataObj.getdescription());
			
		}
		
		newDataObj.setlang(oldDataObj.getlang());
		
		if(cdo.getINTERESTS()!=null){
			newDataObj.setinterests(cdo.getINTERESTS());
		}else{
			newDataObj.setinterests(oldDataObj.getInterests());
		}
		
		newDataObj.setimagealt(oldDataObj.getimagealt());
		newDataObj.setmform_showadvanced(oldDataObj.getmform_showadvanced());
		
		if(cdo.getWEBSITE()!=null){
			newDataObj.seturl(cdo.getWEBSITE());
		}else{
			newDataObj.seturl(oldDataObj.geturl());
			logger.info("[MOODLE] WEBSITE ::"+oldDataObj.geturl());
		}
		
		
		newDataObj.seticq(oldDataObj.geticq());
		newDataObj.setskype(oldDataObj.getskype());
		newDataObj.setaim(oldDataObj.getaim());
		newDataObj.setyahoo(oldDataObj.getyahoo());
		newDataObj.setmsn(oldDataObj.getmsn());
		newDataObj.setidnumber(oldDataObj.getidnumber());
		newDataObj.setinstitution(oldDataObj.getinstitution());
		newDataObj.setdepartment(oldDataObj.getdepartment());
		
		if(cdo.getHOME_PHONE()!=null){
			newDataObj.setphone1(cdo.getHOME_PHONE());
		}else{
			newDataObj.setphone1(oldDataObj.getphone1());
		}
		
		if(cdo.getMOBLIE()!=null){
			newDataObj.setphone2(cdo.getMOBLIE());
		}else{
			newDataObj.setphone2(oldDataObj.getphone2());
		}
		
		if(cdo.getADDRESS()!=null){
			newDataObj.setaddress(cdo.getADDRESS());
		}else{
			newDataObj.setaddress(oldDataObj.getaddress());
		}
		newDataObj.setsubmitbutton(oldDataObj.getsubmitbutton());
	}


	
	

}
